//
//  TTRecyclingCommitGoodsViewCell.m
//  TaoTuo
//
//  Created by LG on 2020/9/13.
//  Copyright © 2020 刘广. All rights reserved.
//

#import "TTRecyclingCommitGoodsViewCell.h"

@interface TTRecyclingCommitGoodsViewCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UIImageView *goodsImgView;
@property (nonatomic, strong) UILabel *titleLabel;

@end

@implementation TTRecyclingCommitGoodsViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self setupSubviews];
        
    }
    return self;
}

- (void)setModel:(TTRecyclingDetailModel *)model
{
    _model = model;
    NSString *urlStr = @"";
    TTDetailBannerModel *bannerModel = model.BannerImages.firstObject;
    if (bannerModel.FileType == 0) {
        urlStr = bannerModel.ImageUrl;
    } else {
        urlStr = bannerModel.VideoCoverImage;
    }
    
    if ([urlStr length] > 0) {
        [self.goodsImgView sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:[UIImage imageNamed:@"f_placeholder_img"] options:SDWebImageRetryFailed];
    }
    self.titleLabel.text = model.Title;
    
}

- (void)setupSubviews
{
    _bgView = [[UIView alloc] init];
    _bgView.backgroundColor = UIColor.whiteColor;
    _bgView.layer.cornerRadius = 6;
    _bgView.layer.shadowColor = UIColorHex(#6721B7).CGColor;
    _bgView.layer.shadowOpacity = 0.1;
    _bgView.layer.shadowOffset = CGSizeZero;
    [self.contentView addSubview:_bgView];
    [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(10);
        make.left.equalTo(self.contentView).mas_offset(10);
        make.right.equalTo(self.contentView.mas_right).mas_offset(-10);
        make.bottom.equalTo(self.contentView.mas_bottom).mas_offset(-15);
    }];
    
    _goodsImgView = [[UIImageView alloc] init];
    _goodsImgView.contentMode = UIViewContentModeScaleAspectFill;
    _goodsImgView.layer.cornerRadius = 5;
    _goodsImgView.layer.masksToBounds = YES;
    [self.bgView addSubview:_goodsImgView];
    [_goodsImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(10);
        make.left.mas_equalTo(10);
        make.width.height.mas_equalTo(65);
    }];
    
    _titleLabel = [UILabel labelWithTitle:@"" color:UIColorHex(333333) font:[UIFont boldSystemFontOfSize:15]];
    _titleLabel.numberOfLines = 0;
    [self.bgView addSubview:_titleLabel];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.left.equalTo(self.goodsImgView.mas_right).mas_offset(15);
        make.right.equalTo(self.contentView.mas_right).mas_offset(-10);
    }];
    
    
    [self.contentView layoutIfNeeded];
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_WIDTH - 20, 85) cornerRadius:6];
    self.bgView.layer.shadowPath = path.CGPath;
    
}

@end
